home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 January: Mac OS SDK / Dev.CD Jan 96 SDK / Dev.CD Jan 96 SDK1.toast / Development Kits (Disc 1) / QuickDraw™ GX / Programming Stuff / Sample Code / Printing Samples / Printer Drivers… / ImageWriterLQ (alt. rdip) / ChooserSupport.c < prev    next >
Encoding:
Text File  |  1995-04-10  |  10.3 KB  |  354 lines  |  [TEXT/MPS ]

  1. /*---------------------------------------------------------------------------
  2. FILENAME
  3.     ChooserSupport.c
  4.  
  5. DESCRIPTION
  6.     This file contains the C code for the PACK and LDEF routines used by the
  7.     Chooser when the ImageWriter LQ driver is selected in the Chooser.
  8.         
  9. COPYRIGHT
  10.     Copyright Apple Computer, Inc. 1992-1994
  11.     All rights reserved. 
  12.     
  13. INTERFACE ROUTINES:
  14.     Device
  15.     LDEF
  16.     
  17.     12/20/93 - dmh - Sync'd with the shipping 1.0b3 GX driver.
  18.      8/28/94 - dmh - Sync'd with the shipping 1.0.1 GX driver.
  19.      8/28/94 - dmh - Universalized code.
  20.  
  21. -------------------------------------------------------------------------------- */
  22.  
  23. // Include the standard Mac header files 
  24. #include "MacIncludes.h"
  25.  
  26. // Include the new QuickDraw GX graphics header files 
  27. #include <graphics routines.h>
  28.  
  29. // Include the required Printing Manager header files 
  30. #include <PrintingDrivers.h>
  31.  
  32. /*********************************************************************************
  33.  *                                         CONSTANTS                                                     *
  34.  *********************************************************************************/
  35.  
  36. // Chooser initialize message selector
  37. #define    initializeMsg            11
  38.  
  39. // Icon Suite support
  40.  
  41. #define    ttNone                    0x0000
  42. #define    ttDisabled                0x0001
  43. #define    ttOffline                0x0002
  44. #define    ttOpen                    0x0003
  45. #define    ttSelected                 0x4000
  46. #define    ttSelectedDisabled    (ttSelected + ttDisabled)
  47. #define    ttSelectedOffline        (ttSelected + ttOffline)
  48. #define    ttSelectedOpen            (ttSelected + ttOpen)
  49.  
  50. #define    ttLabel0                    0x0000
  51. #define    ttLabel1                    0x0100
  52. #define    ttLabel2                    0x0200
  53. #define    ttLabel3                    0x0300
  54. #define    ttLabel4                    0x0400
  55. #define    ttLabel5                    0x0500
  56. #define    ttLabel6                    0x0600
  57. #define    ttLabel7                    0x0700
  58.  
  59.  
  60. /*********************************************************************************
  61.  *                                    INLINE DECLARATIONS                                            *
  62. **********************************************************************************/
  63.  
  64. pascal OSErr PlotIconSuite(const Rect * theRect, short align, short iconTransform, Handle cIcon)
  65.     = {0x303C, 0x0603, 0xABC9};
  66.  
  67. pascal void OldDrawText(const void *textBuf,short firstByte,short byteCount)
  68.     = 0xA885; 
  69.  
  70.  
  71. /***************************************************************************************
  72. *                                         INTERFACE ROUTINES                                                     *
  73. ***************************************************************************************/                        
  74.  
  75.  
  76. /****************************************************************************************
  77.  
  78.                             Device
  79.                             
  80.     function:
  81.                 This routine is the interface routine for the Chooser PACK.  This is the
  82.                 routine the Chooser calls to perform the Chooser functions for the 
  83.                 ImageWriter LQ driver.
  84.                 
  85.     parameters:                
  86.                 message        specifies which Chooser function to perform    
  87.                 caller        equals 1; specifies the caller is the Chooser
  88.                 objName        name of the selected device
  89.                 zoneName        zone name for AppleTalk devices
  90.                 theList        the list of names
  91.                 p2                parameter used depending upon message value
  92.                 
  93.     returns:
  94.                 OSErr
  95.     
  96. ****************************************************************************************/
  97. pascal OSErr Device(short message, short caller, StringPtr objName, 
  98.                     StringPtr zoneName, ListHandle theList, long p2)
  99. {
  100.     
  101.     OSErr            anErr = noErr;
  102.     extern Str31     gDriverName;
  103.     StringPtr        pDriverName = &gDriverName;
  104.     extern gxJob    gJob;                        // Declared in our .a file.
  105.     gxJob            *pJob = &gJob;
  106.  
  107.     if (message == initializeMsg)    // InitializeMsg--start up GX
  108.     {
  109.         FCBPBRec    pb;
  110.  
  111.     /*
  112.         Get the name of our driver for GXHandleChooserMessage.
  113.         (The user may have renamed us.)
  114.     */
  115.         pb.ioCompletion     = nil;
  116.         pb.ioNamePtr         = pDriverName;
  117.         pb.ioVRefNum         = 0;
  118.         pb.ioRefNum         = CurResFile();
  119.         pb.ioFCBIndx         = 0;
  120.         anErr = PBGetFCBInfo(&pb, false);
  121.  
  122.     /*
  123.         Clear *pJob, because it hasn't been initialized yet.  That doesn't
  124.         happen until we pass GXHandleChooserMessage an initializeMsg.
  125.     */
  126.         *pJob = nil;
  127.  
  128.     /*
  129.         We need to initialize GX printing so that we can call
  130.         GXHandleChooserMessage.  Since printing requires a graphics
  131.         client, call GXEnterGraphics first.  If there are errors,
  132.         (for example, due to memory limitations), post an alert.
  133.     */
  134.         if (anErr == noErr)
  135.         {
  136.             GXEnterGraphics();
  137.             anErr = GXGetGraphicsError(nil);
  138.             if (anErr == noErr)
  139.             {
  140.                 anErr = GXInitPrinting();
  141.                 if (anErr != noErr)
  142.                     GXExitGraphics();
  143.             }
  144.                 
  145.             if (anErr != noErr)
  146.                 StopAlert(-4095, nil);
  147.         }
  148.     }
  149.  
  150. /*
  151.     If the Chooser hasn't created a job yet, do nothing unless we were
  152.     sent an initializeMsg.  In its default implementation of
  153.     GXHandleChooserMessage, QuickDraw GX will create the job for our
  154.     driver when it receives an initializeMsg.  It will store a reference
  155.     to it in our pJob pointer.
  156.     
  157.     For all other messages, if a job has been created, call
  158.     GXHandleChooserMessage to handle things.
  159. */
  160.     if (anErr == noErr)
  161.     {
  162.         if ((*pJob != nil) || (message == initializeMsg))
  163.         {
  164.             anErr = GXHandleChooserMessage(pJob, pDriverName, message, caller, objName, zoneName, theList, p2);
  165.     
  166.         /*
  167.             If we just got a terminateMsg, and p2 is also terminateMsg, the
  168.             Chooser is closing.  QuickDraw GX just disposed of the gxJob it
  169.             created earlier when GXHandleChooserMessage was passed
  170.             initializeMsg, so we just need to call GXExitPrinting and
  171.             GXExitGraphics to clean up.
  172.             
  173.             Note that we must test the p2 parameter, because the Chooser
  174.             can also send terminateMsg when it wants to empty the device
  175.             list, but not dispose of us.  For example, this will happen
  176.             when the user turns off AppleTalk in the Chooser.
  177.         */
  178.             if ((message == terminateMsg) && (p2 == terminateMsg))
  179.             {
  180.                 GXExitPrinting();
  181.                 GXExitGraphics();
  182.             }
  183.         }
  184.     }
  185.         
  186.     return(anErr);
  187.     
  188. } // Device
  189.  
  190.  
  191.  
  192. // ------------------------------------------------------------------------
  193. // ENTRY POINT FOR LDEF
  194. // ------------------------------------------------------------------------
  195.  
  196. pascal void LDEF(
  197.     short         message,        // What operation to perform on list
  198.     Boolean     select,            // Is this cell to be selected or not?
  199.     Rect        *theRect,        // Rectangle of this cell, clipped to window
  200.     Cell        theCell,        // Which cell this is
  201.     short        dataOffset,        // Offset into data for this cell
  202.     short        dataLen,        // Length of data for this cell
  203.     ListHandle    theList)        // The list to act upon
  204. /*
  205.     An LDEF that works in two modes:
  206.         - if the first two characters of the cell are valid AppleTalk NBP names (ie, not ≈ ≈)
  207.           then the LDEF is just a basic text LDEF
  208.         - otherwise, it assumes the data is part of a PortListRec, which is
  209.           a structure for icons with text underneath
  210. */
  211.  
  212. {
  213. #pragma unused (theCell, dataLen)
  214.  
  215.     gxPortListRec        theCellContents;
  216.     Rect                iconRect;
  217.     unsigned char        hiliteMode;
  218.     
  219.     switch (message)
  220.         {
  221.         case lDrawMsg:
  222.         case lHiliteMsg:
  223.         
  224.             // save the data to avoid locking things down
  225.             if (dataLen > sizeof(theCellContents) )
  226.                 dataLen = sizeof(theCellContents);
  227.             BlockMove(((*(**theList).cells) + dataOffset), &theCellContents, dataLen );
  228.             
  229.             // draw the cell as an icon, but only if we see our magic marker at the front
  230.             if ( (theCellContents.firstMarker == '≈') && (theCellContents.secondMarker == '≈') )
  231.                 {
  232.                 // center the icon rect on the list with a top margin of 10 pixels
  233.                 iconRect.top = theRect->top + 10;
  234.                 iconRect.left = theRect->left + ((theRect->right - theRect->left) >> 1) - 16;
  235.                 iconRect.bottom = iconRect.top + 32;
  236.                 iconRect.right = iconRect.left + 32;
  237.                 
  238.                 
  239.                 // draw the icon
  240.                 if (theCellContents.iconSuiteHandle != nil)
  241.                     PlotIconSuite(&iconRect,
  242.                             ttNone, (select) ? ttSelected: ttNone,
  243.                             theCellContents.iconSuiteHandle);
  244.                             
  245.                 // Get the general area under the icon in which to draw the label
  246.                 iconRect.left = theRect->left + 2;
  247.                 iconRect.right = iconRect.left + (**theList).cellSize.h - 2;
  248.                 iconRect.top = iconRect.bottom + 2;
  249.                 iconRect.bottom = theRect->bottom;
  250.     
  251.                 // use a nice small font for the label            
  252.                 TextFont(applFont);
  253.                 TextSize(9);
  254.                 
  255.                     {
  256.                     short        labelWidth;
  257.                     short        rectWidth;
  258.                     short        labelHeight;
  259.                     FontInfo    theInfo;
  260.                 
  261.                     // Get rid of any text that was there before
  262.                     EraseRect(&iconRect);
  263.                     iconRect.top += 2;
  264.                     
  265.                     // compute the height of the label                    
  266.                     GetFontInfo(&theInfo);
  267.                     labelHeight = theInfo.ascent + theInfo.leading;
  268.                     
  269.                     // compute where to draw the text
  270.                     iconRect.bottom = iconRect.top + labelHeight;
  271.                     rectWidth = iconRect.right-iconRect.left;
  272.                     
  273.                     // truncate the string to fit within the box
  274.                     TruncString(rectWidth, theCellContents.iconName, smTruncEnd);
  275.                     
  276.                     // compute the new width of the string
  277.                     labelWidth = StringWidth(theCellContents.iconName);
  278.                     
  279.                     // center the string, draw it
  280.                     iconRect.left += (rectWidth >> 1) - (labelWidth >> 1);
  281.                     MoveTo(iconRect.left, iconRect.bottom);
  282.                     DrawString(theCellContents.iconName);
  283.                     
  284.                     if (select)
  285.                         {
  286.                         // compute right and lower edge of box bounding the text we just drew
  287.                         iconRect.right = iconRect.left + labelWidth;
  288.                         iconRect.bottom += theInfo.descent;
  289.                         
  290.                         // outset it, and invert it to select it
  291.                         InsetRect(&iconRect, -1, -1);
  292.                         hiliteMode = LMGetHiliteMode();
  293.                         BitClr(&hiliteMode, pHiliteBit);
  294.                         LMSetHiliteMode(hiliteMode);
  295.                         InvertRect(&iconRect);
  296.                         }
  297.                     }
  298.                     
  299.                 TextFont(applFont);
  300.                 TextSize(0);
  301.                 }
  302.             else
  303.                 {
  304.                 // how boring!  It's only text
  305.                 FontInfo    theInfo;
  306.                 Rect        ourRect;
  307.                 short        cellWidth;
  308.                 
  309.                 // add a margin to the rectangle
  310.                 ourRect = *theRect;
  311.                 ourRect.left += 4;
  312.                 --ourRect.right;
  313.                 cellWidth = ourRect.right - ourRect.left;
  314.                 
  315.                 // erase the rectangle
  316.                 GetFontInfo(&theInfo);
  317.                 EraseRect(theRect);
  318.                 MoveTo(ourRect.left, ourRect.bottom - theInfo.descent);
  319.                 
  320.                 // hey, you can't park that string here -- it's too big!
  321.                 if (TextWidth((Ptr) &theCellContents, 0, dataLen) > cellWidth )
  322.                     {
  323.                     // condense the text first
  324.                     TextFace(condense);
  325.                     
  326.                     // then truncate afterwards
  327.                     TruncText(cellWidth, (Ptr) &theCellContents, &dataLen, smTruncEnd);
  328.                     }
  329.                     
  330.                 // those darn other languages!
  331.                 if (GetSysJust() == teJustRight)
  332.                     Move(cellWidth-TextWidth((Ptr) &theCellContents, 0, dataLen) , 0);
  333.                     
  334.                 OldDrawText((Ptr) &theCellContents, 0, dataLen);
  335.                 
  336.                 // if selected, invert it
  337.                 if (select)
  338.                     {
  339.                     hiliteMode = LMGetHiliteMode();
  340.                     BitClr(&hiliteMode, pHiliteBit);
  341.                     LMSetHiliteMode(hiliteMode);
  342.                     InvertRect(theRect);
  343.                     }
  344.                     
  345.                 // normal text again
  346.                 TextFace(normal);
  347.                 }
  348.                 
  349.             break;
  350.             
  351.         } // switch
  352.         
  353. } // LDEF
  354.